<template>
  <div class="app-container">
  <!-- 嵌入知乎网页，并删除边框和滚动条 -->
 <el-form :model="AiConfig" :rules="rules" ref="AiConfig" size="big" :inline="true"  label-width="100px">
      <el-form-item label="Ai聊天地址" prop="aiChatUrl">
        <el-input
          v-model="AiConfig.aiChatUrl"
          placeholder="请输入Ai聊天地址"
          clearable
          style="width: 240px;"
        />
      </el-form-item>
      <br>
      <el-form-item label="Ai绘画地址" prop="aiPlaneUrl">
        <el-input
          v-model="AiConfig.aiPlaneUrl"
          placeholder="请输入Ai绘画地址"
          clearable
          style="width: 240px;"
        />
      </el-form-item>
      <br>
      <el-form-item  label-width="100px">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="updateAiconfigInfo('Aiconfig')">保存</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>  </div>
</template>

<script>
import { getAiconfig,updateAiconfig } from "@/api/aiconfig/aiconfig.js";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Dept",
  dicts: ['sys_normal_disable'],
  components: { Treeselect },
  data() {
    return {
      refreshTable: true,
      // 查询参数
      AiConfig: {
        aiChatUrl: "",
        aiPlaneUrl: ""
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        aiChatUrl: [
          { required: true, message: "Ai聊天地址不能为空", trigger: "blur" }
        ],
        aiPlaneUrl: [
          { required: true, message: "Ai绘画地址不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getAiconfigInfo();
  },
  methods: {
    getAiconfigInfo() {
      this.loading = true;
      getAiconfig().then(res => {
        console.log(res);
      this.AiConfig.aiChatUrl = res.data.aiChatUrl;
      this.AiConfig.aiPlaneUrl = res.data.aiPlaneUrl;
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.AiConfig.aiChatUrl = undefined;
      this.AiConfig.aiPlaneUrl = undefined;
    },
    /** 提交按钮 */
    updateAiconfigInfo() {        
      this.$refs["AiConfig"].validate(valid => {
        if (valid) {
            updateAiconfig(this.AiConfig).then(response => {
              this.$modal.msgSuccess("配置成功");
              this.getAiconfigInfo();
        })
        }
      });
    },
  }
};
</script>
